<%@ page language="java"  pageEncoding="UTF-8" %>
<%@include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<style type="text/css">
		<!--
		.STYLE1 {font-weight: bold}
		-->
	</style>
	<script type="text/javascript" src="${resRoot}/js/alert_message.js"></script>
	<body class="no-skin" scroll=no>
		<!-- 以下为内容 -->
		<div class="main-content1">



		<!-- /section:basics/content.breadcrumbs -->
		<div class="page-content">





			<div class="row">

				<div class="col-xs-12" >
					<!-- PAGE CONTENT BEGINS -->
					<div class="widget-box transparent">

						<div class="widget-header widget-header-small">
							<h4 class="widget-title blue smaller">
								<i class="ace-icon fa fa-rss orange"></i>
								菜单信息</h4>

								<div class="widget-toolbar">


									<a href="#" onclick="to_submit();" class="blue" id="editS">
										<i class="ace-icon fa fa-save "></i> 保存菜单信息										
									</a>

								</div>
						</div>

						<div class="widget-body">
						<div class="widget-main padding-0">
										<!-- #section:pages/profile.feed -->
						<div id="profile-feed-1" class="profile-feed">
											<form id="form1" class="form-horizontal" role="form">
											
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">父级菜单</label>
	                                    			<div class="col-sm-9">
												        <select id="menu" name="parentCode" class="col-xs-9">
                                                        </select>
													</div>
                                  				</div>
                                  				
												<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单代码</label>
	                                    			<div class="col-sm-9">
														<input name="menuCode" type="text"  value="${menu.menuCode}" maxlength="50" class="col-xs-9" readonly />
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单名称</label>
	                                    			<div class="col-sm-9">
														<input name="menuName" type="text"  value="${menu.menuName}" maxlength="50" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单路径</label>
	                                    			<div class="col-sm-9">
														<input name="url" type="text" id="url" value="${menu.url}" maxlength="200" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">描述</label>
	                                    			<div class="col-sm-9">
														<textarea name="remark" rows="5" class="col-xs-9" id="remark">${menu.remark}</textarea>
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单类型</label>
	                                    			<div class="col-sm-9">
	                                                     <input name="menuType" type="radio" value="P" ${menu.menuType=="P"?"checked":""} />业务菜单 &nbsp;&nbsp;
	                                                     <input type="radio" name="menuType" value="S" ${menu.menuType=="S"?"checked":""} />仅管理员可见
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">排序序号</label>
	                                    			<div class="col-sm-9">
														<input name="orderId" type="text"  value="${menu.orderId}" maxlength="10" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单图标</label>
	                                    			<div class="col-sm-9">
														<input name="icon" type="text"  value="${menu.icon}" maxlength="100" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">菜单打开图标</label>
	                                    			<div class="col-sm-9">
														<input name="iconopen" type="text"  value="${menu.iconopen}" maxlength="100" class="col-xs-9" />
													</div>
                                  				</div>
                                  				
                                  				<div class="space-1"></div>
                                				<div class="form-group">
                                    				<label class="col-sm-3 control-label no-padding-right" for="form-field-1">状态</label>
	                                    			<div class="col-sm-9">
														<input name="status" type="radio" value="1"  <c:if test="${menu.status== 1}">checked</c:if>  />
															有效&nbsp;&nbsp;
														<input type="radio" name="status" value="0"  <c:if test="${menu.status== 0}">checked</c:if>/>
															无效
													</div>
                                  				</div>
											</form>
										</div>


																	<div class="widget-box transparent" style=" margin-bottom:0;">
																		<div class="widget-header widget-header-small">
																			<h4 class="widget-title blue smaller">
																				<i class="ace-icon glyphicon glyphicon-cog orange"></i>
																				按钮维护</h4>

																				<div class="widget-toolbar">


																					<a  href="#modal-table"   data-toggle="modal" class="blue" id="editS">
																						<i class="ace-icon glyphicon glyphicon-plus "></i> 添加按钮												</a>
																					</div>
																				</div>
																			</div>

																			<div style="overflow-x:auto;   height:200px">
																				<table id="sample-table-1" class="table table-striped table-bordered table-hover" style="margin:0; "  >
																					<thead>
																						<tr>
																							<th align="center" nowrap="nowrap" class="center">序号</th>
																							<th nowrap="nowrap" ><strong>按钮代码</strong></th>
																								<th nowrap="nowrap" ><strong>按钮名称</strong></th>
																									<th nowrap="nowrap" >操作</th>
																								</tr>
																							</thead>
																							<tbody>
																								<c:forEach items="${resources}" var="resource" varStatus="status">
																									<tr>
																										<td align="center" class="center">${status.index+1}</td>
																										<td>${resource.resourceCode}</td>
																										<td>${resource.resourceName}</td>
																										<td align="center"><a href="#" onclick="toDelButton('${resource.resourceCode}');">删除</a></td>
																									</tr>
																								</c:forEach>
																							</tbody>
																						</table>
																					</div>
																					<div  >


																						<button class="btn" type="button" style="margin-left:40%;"  onclick="window.location.href='forwardMenuChildrenList.htm?parentCode=${menu.parentCode}'">
																							<i class="ace-icon fa fa-undo bigger-110"></i>
																						返 回									</button>

																					</div>
																				</div>
																			</div>
																		</div>



																	</div>




																	<!-- /.col -->

																</div>

																<!-- /.row -->
															</div><!-- /.page-content -->
														</div><!-- /.main-content -->

														<div id="modal-table" class="modal fade" tabindex="-1" style=" height:auto; overflow:auto">
															<div class="modal-dialog" style="width:400px;height:auto">
																<div class="modal-content" >
																	<div class="modal-header no-padding">
																		<div class="table-header">
																			添加按钮
																			<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
																				<span class="white">&times;</span>
																			</button>

																		</div>
																	</div>

																	<div class="modal-body no-padding" >
																		<form id="form2">
																			<table width='80%' border='0' align="center" style="margin:20px auto auto 20px;">
																				<tr>
																					<td width='12%' height="50" align='right' nowrap='nowrap'><strong>按钮代码：</strong></td>
																						<td ><input name='resourceCode' type='text' id='resourceCode' maxlength="50"  class='col-xs-10'>  </td>
																					</tr>
																					<tr>
																						<td height="50" align='right' nowrap='nowrap'><strong>按钮名称：</strong></td>
																							<td><input name='resourceName' type='text' id='resourceName' maxlength="100"  class='col-xs-10' /></td>
																						</tr>
																					</table>
																				</form>
																				<div class="col-xs-12" style="text-align:center; background:#fff; padding:0; height:40px; ">
																					<!-- 按钮行-->
																					<button class="btn btn-info btn-sm" type="button" data-dismiss="modal"  onclick="do_saveButtonParam();"> <i class="ace-icon fa fa-save "></i> 保 存 </button>
																					</div>

																					</div>


																					<a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
																					<i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>			</a>		</div><!-- /.main-container -->
																					<div class="col-xs-12" style="text-align:center">


																					</div>


																					<script src="${resRoot}/plugin/ace-v1.3/assets/js/jquery.validate.min.js"></script>
																					<script src="${resRoot}/plugin/jquery-validation/localization/messages_zh.js"></script>
																					<script type="text/javascript">

																						//全局变量  保存menucode信息
																						var selectmenucode='${menu.parentCode}';

																						var menucode='${menu.menuCode}';

																						jQuery(function($){
																							//加载父级菜单
																							showParentMenu();
																							validateForm();
																							//$("#menu").bind("change",showParentMenu);
																						});
																						
																						function to_submit(){
																						    	$("#form1").submit();
																						    }

																						//ajax加载父级下拉框
																						function showParentMenu(){
																							var parentCode='${menu.parentCode}';
																							$.ajax({
																								url : "findMenuByParentId.json",
																								type : "post",
																								data : {parentCode:0},
																								dataType : "json",
																								success : function(data){
																									if(data.length > 0){
																										var html="";
																										//一级菜单
																										if(selectmenucode==0){
																											html+="<option value='0'>菜单管理</option>";
																										}else{

																											for(var i=0;i<data.length;i++){
																												if(parentCode==data[i].menuCode){
																													html+="<option value='"+data[i].menuCode+"' selected>"+data[i].menuName+"</option>";
																												}else{
																													html+="<option value='"+data[i].menuCode+"'>"+data[i].menuName+"</option>";
																												}
																											}

																										}
																										$("#menu").append(html);
																									}
																								},
																								error : function(){
																									$.Alert('加载父级菜单出现错误！','','');
																								}
																							});
																						}

																						//ajax提交保存菜单信息
																						function do_menusave(){
																								var remarktrim=$.trim($("#remark").val());
																								$("#remark").val(remarktrim);
																								var urltrim=$.trim($("#url").val());
																								$("#url").val(urltrim);
																								$.ajax({
																									url : "editMenu.json",
																									type : "post",
																									data : $("#form1").serializeObject(),
																									dataType : "json",
																									success : function(data){
																										$.Alert(data.message,'',reloadEdit);
																									},
																									error : function(){
																										$.Alert('菜单代码已存在，请重新修改！','','');
																									}
																								});
																							}
																							
																						function validateForm(){
																							return $("#form1").validate({
																								errorElement : 'span',
																								errorClass : 'help-block',
																								focusInvalid : false,
																								rules : {
																									"menuName" : {
																										required : true
																									},
																									"url" : {
																										required : true
																									},
																									"remark" : {
																										required : true,
																										maxlength:500
																									},
																									"orderId" : {
																										required : true,
																										number:true
																									}
																								},
																								highlight: function (e) {
																									$(e).closest('.form-group').removeClass('has-info').addClass('has-error');
																								},
																								success: function (e) {
																									$(e).closest('.form-group').removeClass('has-error');//.addClass('has-info');
																									$(e).remove();
																								},
																								errorPlacement: function (error, element) {
																									if(element.is(':checkbox') || element.is(':radio')) {
																										var controls = element.closest('div[class*="col-"]');
																										if(controls.find(':checkbox,:radio').length > 1) controls.append(error);
																										else error.insertAfter(element.nextAll('.lbl:eq(0)').eq(0));
																										}
																										else if(element.is('.select2')) {
																											error.insertAfter(element.siblings('[class*="select2-container"]:eq(0)'));
																										}
																										else if(element.is('.chosen-select')) {
																											error.insertAfter(element.siblings('[class*="chosen-container"]:eq(0)'));
																										}
																										else if(element.is('textarea')) {
																											error.appendTo(element.parent());
																										}
																										else if(element.is('input[type=text]')) {
																											error.appendTo(element.parent());
																										}
																										else error.insertAfter(element.parent());
																										},
																										submitHandler: function (form) {
																											do_menusave();
																										},
																										invalidHandler: function (form) {
																										}
																									});
																								}
																								function do_saveButtonParam(){
																									var resourceCode=$.trim($("#resourceCode").val());
																									var resourceName=$.trim($("#resourceName").val());
																									if(resourceCode==""){
																										$.Alert('按钮代码不能为空！','','');
																										return false;
																									}
																									
																									var reg = /^[a-zA-Z0-9_]*$/;
																									if(!reg.test(resourceCode)){
																										$.Alert('按钮代码只能为字母、下划线和数字！');
																										return;
																									}
																									
																									if(resourceName==""){
																										$.Alert('按钮名称不能为空！','','');
																										return false;
																									}
																									var formdata='resourceCode='+resourceCode+'&resourceName='+resourceName+'&menuCode='+menucode;
																									$.ajax({
																										url : "insertButton.json",
																										type : "post",
																										data : formdata,
																										dataType : "json",
																										success : function(data){
																											if("1"==data.code){
																												$.Alert(data.message,'',reloadpage);
																											}else{
																												$.Alert(data.message);
																											}
																										},
																										error : function(){
																											$.Alert('按钮代码已存在，请重新填写！','','');
																										}
																									});
																								}
																								
																								function reloadpage(){
																									window.location.reload();
																								}

																								function toDelButton(resourceCode){
																									$.Confirm('请确认是否删除该按钮？','',function(){
																									delButton(resourceCode);
																								});
																							}


																							function delButton(resourceCode){
																								$.ajax({
																									url : "delButton.json",
																									type : "post",
																									data : "resourceCode="+resourceCode,
																									dataType : "json",
																									success : function(data){
																										$.Alert(data.message,'','');
																										window.location.reload();
																										// window.location.href='forwardMenuChildrenList.htm?status=-1';
																									}
																								});
																							}
																							
																							function reloadEdit(){
																								editRefresh(0);
																								window.location.reload();
																							}
																							
																							function editRefresh(typeVal){
																								parent.refreshTree(typeVal);
																							}
																							
																							
																							//处理键盘事件 禁止后退键（Backspace）密码或单行、多行文本框除外  
        function forbidBackSpace(e) {  
            var ev = e || window.event; //获取event对象   
            var obj = ev.target || ev.srcElement; //获取事件源   
            var t = obj.type || obj.getAttribute('type'); //获取事件源类型   
            //获取作为判断条件的事件类型   
            var vReadOnly = obj.readOnly;  
            var vDisabled = obj.disabled;  
            //处理undefined值情况   
            vReadOnly = (vReadOnly == undefined) ? false : vReadOnly;  
            vDisabled = (vDisabled == undefined) ? true : vDisabled;  
            //当敲Backspace键时，事件源类型为密码或单行、多行文本的，   
            //并且readOnly属性为true或disabled属性为true的，则退格键失效   
            var flag1 = ev.keyCode == 8 && (t == "password" || t == "text" || t == "textarea") && (vReadOnly == true || vDisabled == true);  
            //当敲Backspace键时，事件源类型非密码或单行、多行文本的，则退格键失效   
            var flag2 = ev.keyCode == 8 && t != "password" && t != "text" && t != "textarea";  
            //判断   
            if (flag2 || flag1) return false;  
        }  
        //禁止后退键 作用于Firefox、Opera  
        document.onkeypress = forbidBackSpace;  
        //禁止后退键  作用于IE、Chrome  
        document.onkeydown = forbidBackSpace; 


																						</script>
